package test;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;

public class ImageViewer extends JFrame {
    private JLabel imageLabel;

    public ImageViewer(byte[] imageData) {
        imageLabel = new JLabel();
        add(imageLabel, BorderLayout.CENTER);

        try {
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData));
            imageLabel.setIcon(new ImageIcon(image));
        } catch (IOException e) {
            e.printStackTrace();
        }

        pack();
        setVisible(true);
    }

    public static void main(String[] args) throws Exception {
        // 存储图片
        StoreImage.storeImage("image.jpg");

        // 读取图片
        byte[] imageData = RetrieveImage.retrieveImage(1);

        // 展示图片
        ImageViewer viewer = new ImageViewer(imageData);
    }
}
